# Maintainer: Peter Budai <peterbudai@hotmail.com>

_realname=joblib
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-${_realname}"  "${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=0.14.0
pkgrel=1
pkgdesc="Set of tools to provide lightweight pipelining in Python (mingw-w64)"
arch=('any')
url='https://joblib.readthedocs.io/'
license=('BSD')
makedepends=("${MINGW_PACKAGE_PREFIX}-python2"
             "${MINGW_PACKAGE_PREFIX}-python3"
             "${MINGW_PACKAGE_PREFIX}-python3-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python2-setuptools")
source=("${_realname}-${pkgver}.tar.gz::https://github.com/joblib/joblib/archive/${pkgver}.tar.gz")
sha256sums=('9e66f3e31669f772fcbad95043fd05e4530e78288d60363b785d4c288a5dc707')

prepare() {
  for pver in {2,3}; do
    rm -rf python${pver}-build-${CARCH} | true
    cp -r "${_realname}-${pkgver}" "python${pver}-build-${CARCH}"
  done

  # python -> python2 rename
  find python2-build-${CARCH} -name '*py' -exec sed -e 's_#!/usr/bin/env python_&2_' -i {} \;

}

build() {
  for pver in {2,3}; do
    msg "Python ${pver} build for ${CARCH}"
    cd "${srcdir}/python${pver}-build-${CARCH}"
    ${MINGW_PREFIX}/bin/python${pver} setup.py build
  done
}

package_python3-joblib() {
  depends=("${MINGW_PACKAGE_PREFIX}-python3")
  optdepends=("${MINGW_PACKAGE_PREFIX}-python3-numpy: for array manipulation"
              "${MINGW_PACKAGE_PREFIX}-python3-lz4: for compressed serialization")

  cd "${srcdir}/python3-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENSE.txt "${pkgdir}"${MINGW_PREFIX}/share/licenses/python3-${_realname}/LICENSE
}

package_python2-joblib() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2")
  optdepends=("${MINGW_PACKAGE_PREFIX}-python2-numpy: for array manipulation"
              "${MINGW_PACKAGE_PREFIX}-python2-lz4: for compressed serialization")

  cd "${srcdir}/python2-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENSE.txt "${pkgdir}"${MINGW_PREFIX}/share/licenses/python2-${_realname}/LICENSE
}

package_mingw-w64-i686-python2-joblib() {
  package_python2-joblib
}

package_mingw-w64-i686-python3-joblib() {
  package_python3-joblib
}

package_mingw-w64-x86_64-python2-joblib() {
  package_python2-joblib
}

package_mingw-w64-x86_64-python3-joblib() {
  package_python3-joblib
}
